// @FileName  :memory.c
// @Time      :2024/5/11 11:21
// @Author    :YKW
//# include <bits/stdc++.h>
//using namescurace std;
# include <stdio.h>
# include <stdlib.h>

typedef struct node {
    int st, sz;
    struct node *nxt;
} *node;
node head = NULL, cur, t, q, pri;
int n, i, j, st, sz, a;

int main() {
    scanf("%d", &n);
    while (n--) {
        scanf("%d %d", &st, &sz);
        if (head == NULL) {
            cur = (struct node *) malloc(sizeof(struct node));
            head = cur;
        } else {
            cur->nxt = (struct node *) malloc(sizeof(struct node));
            cur = cur->nxt;
        }
        cur->st = st, cur->sz = sz, cur->nxt = NULL;
    }
    cur->nxt = head;
    pri = cur;
    cur = head;

    //模拟请求
    while (scanf("%d", &a)) {
        if (a == -1) break;
        else {
            if (pri->nxt->sz == a) {//删除当前节点
                q = cur;
                cur = cur->nxt;
                pri->nxt = cur;
                free(q);
            } else if (cur->sz > a)//释放部分内存
                cur->sz -= a;
            else {
                t = cur;
                while (cur->nxt != t) {
                    if (cur->nxt->sz > a) {
                        cur->nxt->sz -= a;
                        pri = cur;
                        cur = cur->nxt;
                        break;
                    } else if (cur->nxt->sz == a) {
                        pri = cur;
                        q = cur->nxt;
                        cur->nxt = cur->nxt->nxt;
                        cur = cur->nxt;
                        free(q);
                        break;
                    } else {
                        pri = cur;
                        cur = cur->nxt;
                    }
                }
                if (cur->nxt == t)
                    pri = cur, cur = t;
            }
        }
    }
    printf("%d %d\n", cur->st, cur->sz);
    t = cur->nxt;
    while (t != cur) {
        printf("%d %d\n", t->st, t->sz);
        t = t->nxt;
    }
    return 0;
}
/*
12
1024 512
8192 512
16384 1024
32768 3072
65536 8192
77824 1024
80896 8192
96016 1024
101136 5120
119328 512
134448 1024
142640 3072
1024 2560 10240 512 2048 6400 2560 5600 2000 -1
 */
